package paneles;
import java.awt.BorderLayout;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;

import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.text.MaskFormatter;

import datos.Cliente;
import dialogos.ClienteDialogo;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class PanelClientes extends javax.swing.JPanel {
	private JLabel lNombre;
	private JTextField tNombre;
	private JButton bCancelar;
	private JButton bAceptar;
	private JButton bExaminar;
	private JLabel lFoto;
	private JPanel jPanel;
	private JTextField tCelular;
	private JLabel lCelular;
	private JTextField tEmail;
	private JLabel lEmail;
	private JTextField tTelefono;
	private JLabel lTelefono;
	private JTextField tDireccion;
	private JLabel lDireccion;
	private JTextField tApellido;
	private JLabel lApellido;
	private String ruta;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new PanelClientes());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	public PanelClientes() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			FlowLayout thisLayout = new FlowLayout();
			thisLayout.setVgap(10);
			thisLayout.setHgap(10);
			this.ruta = "";
		this.setLayout(thisLayout);
			this.setPreferredSize(new java.awt.Dimension(323, 346));
			{
				lNombre = new JLabel();
				this.add(lNombre);
				lNombre.setText("Nombre");
				lNombre.setPreferredSize(new java.awt.Dimension(92, 21));
				lNombre.setHorizontalAlignment(SwingConstants.CENTER);
				lNombre.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				lNombre.setForeground(new java.awt.Color(0,0,0));
			}
			{
				tNombre = new JTextField();
				this.add(tNombre);
				tNombre.setPreferredSize(new java.awt.Dimension(200, 21));
				tNombre.setSize(180, 21);
				tNombre.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
			}
			{
				lApellido = new JLabel();
				this.add(lApellido);
				lApellido.setText("Apellido");
				lApellido.setPreferredSize(new java.awt.Dimension(92, 21));
				lApellido.setHorizontalAlignment(SwingConstants.CENTER);
				lApellido.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				lApellido.setForeground(new java.awt.Color(0,0,0));
			}
			{
				tApellido = new JTextField();
				this.add(tApellido);
				tApellido.setPreferredSize(new java.awt.Dimension(200, 21));
				tApellido.setSize(180, 21);
				tApellido.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
			}
			{
				lDireccion = new JLabel();
				this.add(lDireccion);
				lDireccion.setText("Direccion");
				lDireccion.setPreferredSize(new java.awt.Dimension(92, 21));
				lDireccion.setHorizontalAlignment(SwingConstants.CENTER);
				lDireccion.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				lDireccion.setForeground(new java.awt.Color(0,0,0));
			}
			{
				tDireccion = new JTextField();
				this.add(tDireccion);
				tDireccion.setPreferredSize(new java.awt.Dimension(200, 21));
				tDireccion.setSize(180, 21);
				tDireccion.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
			}
			{
				lTelefono = new JLabel();
				this.add(lTelefono);
				lTelefono.setText("Telefono");
				lTelefono.setPreferredSize(new java.awt.Dimension(92, 21));
				lTelefono.setHorizontalAlignment(SwingConstants.CENTER);
				lTelefono.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				lTelefono.setForeground(new java.awt.Color(0,0,0));
			}
			{
				tTelefono = new JTextField();
				this.add(tTelefono);
				tTelefono.setPreferredSize(new java.awt.Dimension(200, 21));
				tTelefono.setSize(180, 21);
				tTelefono.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
			}
			{
				lCelular = new JLabel();
				this.add(lCelular);
				lCelular.setText("Celular");
				lCelular.setPreferredSize(new java.awt.Dimension(92, 21));
				lCelular.setHorizontalAlignment(SwingConstants.CENTER);
				lCelular.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				lCelular.setForeground(new java.awt.Color(0,0,0));
			}
			{
				tCelular = new JTextField();
				this.add(tCelular);
				tCelular.setPreferredSize(new java.awt.Dimension(200, 21));
				tCelular.setSize(180, 21);
				tCelular.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
			}
			{
				lEmail = new JLabel();
				this.add(lEmail);
				lEmail.setText("Email");
				lEmail.setPreferredSize(new java.awt.Dimension(92, 21));
				lEmail.setHorizontalAlignment(SwingConstants.CENTER);
				lEmail.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
				lEmail.setForeground(new java.awt.Color(0,0,0));
			}
			{
				tEmail = new JTextField();
				this.add(tEmail);
				tEmail.setPreferredSize(new java.awt.Dimension(200, 21));
				tEmail.setSize(180, 21);
				tEmail.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
			}
			{
				jPanel = new JPanel();
				BorderLayout jPanelLayout = new BorderLayout();
				jPanel.setLayout(jPanelLayout);
				this.add(jPanel);
				jPanel.setPreferredSize(new java.awt.Dimension(100, 100));
				{
					lFoto = new JLabel();
					jPanel.add(lFoto, BorderLayout.CENTER);
					lFoto.setText("Foto");
					lFoto.setHorizontalAlignment(SwingConstants.CENTER);
					lFoto.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
					lFoto.setSize(100, 100);
					lFoto.setPreferredSize(new java.awt.Dimension(100, 100));
				}
			}
			{
				bExaminar = new JButton();
				this.add(bExaminar);
				bExaminar.setText("Examinar...");
				bExaminar.setPreferredSize(new java.awt.Dimension(115, 25));
				bExaminar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						JFileChooser filechooser = new JFileChooser();
						FileNameExtensionFilter filtro = new FileNameExtensionFilter("Archivos de imagen", "jpg", "bmp", "gif", "png");
						filechooser.setFileFilter(filtro);
						int returnVal = filechooser.showOpenDialog(PanelClientes.this.getParent());
						if (returnVal == JFileChooser.APPROVE_OPTION){
							PanelClientes.this.lFoto.setText("");
							ImageIcon imagen = new ImageIcon(filechooser.getSelectedFile().getPath());
							ImageIcon foto = new ImageIcon(imagen.getImage().getScaledInstance(lFoto.getWidth(), lFoto.getHeight(), Image.SCALE_SMOOTH));
							PanelClientes.this.lFoto.setIcon(foto);
							PanelClientes.this.ruta = filechooser.getSelectedFile().getPath();
						}
					}
				});
			}
			{
				bAceptar = new JButton();
				this.add(bAceptar);
				bAceptar.setText("Aceptar");
				bAceptar.setSize(100, 25);
				bAceptar.setPreferredSize(new java.awt.Dimension(100, 25));
			}
			{
				bCancelar = new JButton();
				this.add(bCancelar);
				bCancelar.setText("Cancelar");
				bCancelar.setSize(100, 25);
				bCancelar.setPreferredSize(new java.awt.Dimension(100, 25));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public JButton getBCancelar() {
		return bCancelar;
	}

	public void setBCancelar(JButton cancelar) {
		bCancelar = cancelar;
	}

	public JButton getBAceptar() {
		return bAceptar;
	}

	public void setBAceptar(JButton aceptar) {
		bAceptar = aceptar;
	}

	public Cliente getCliente() {
		Cliente c=new Cliente();
		c.setApellido(this.tApellido.getText());
		c.setCelular(tCelular.getText());
		c.setDireccion(tDireccion.getText());
		c.setEmail(tEmail.getText());
		c.setTelefono(tTelefono.getText());
		c.setNombre(this.tNombre.getText());
		c.setFoto(ruta);
		return c;
	}

	public void cargarCliente(Cliente c) {
		this.tApellido.setText(c.getApellido());
		this.tCelular.setText(c.getCelular().toString());
		this.tDireccion.setText(c.getDireccion());
		this.tEmail.setText(c.getEmail());
		this.tNombre.setText(c.getNombre());
		this.tTelefono.setText(c.getTelefono().toString());
		/*try{
			this.lFoto.setIcon(new ImageIcon(c.getFoto()));
			this.ruta = c.getFoto();
		}
		catch (Exception e){
			e.printStackTrace();
		}	*/
		if(c.getFoto() != null){
			this.lFoto.setIcon(new ImageIcon(c.getFoto()));
			this.ruta = c.getFoto();
		}
		else{
			this.lFoto = new JLabel();
			this.jPanel.repaint();
		}
	}

	public JButton getBExaminar() {
		return bExaminar;
	}

	public JLabel getLFoto() {
		return lFoto;
	}

	public String getRuta() {
		return ruta;
	}

}
